package dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree;

import com.google.gwt.user.client.rpc.IsSerializable;

import java.util.ArrayList;

public class ChildList<T extends GroupItem> extends ArrayList<T> implements IsSerializable {
    private DistributionFilterGroup distributionFilterGroup;


    public ChildList() {
    }


    public ChildList(DistributionFilterGroup distributionFilterGroup) {
        this.distributionFilterGroup = distributionFilterGroup;
    }


    @Override
    public boolean add(T groupItem) {
        boolean res = super.add(groupItem);
        if (res) {
            groupItem.group = distributionFilterGroup;
        }
        return res;
    }

    @Override
    public T remove(int i) {
        GroupItem res = super.remove(i);
        if (res != null) {
            res.group = null;
        }
        return (T) res;
    }
}
